﻿
#If Not (PocketPC Or Smartphone) Then

Imports System.Threading
Imports System.Net
Imports std
Imports xmlctrl

Public Class xmlcontrolHttpServer
    Inherits httpServer2
    Public Shadows Event receive(ByVal context As httpContext, ByRef control As xmlcontrol)

    Private Sub xmlcontrolHttpServer_receive(ByVal context As httpContext) Handles MyBase.receive
        Dim control As xmlcontrol = Nothing
        Try
            RaiseEvent receive(context, control)
        Catch ex As Exception
            raiseError("caught exception in receive, " + context.url().full + ", " + _
                       ex.Message + ", " + ex.StackTrace, errorHandle.errorType.warning)
        End Try
        If Not control Is Nothing Then
            If Not control.render() Then
                raiseError("cannot render xmlcontrol, ignore request.", errorHandle.errorType.warning)
                context.setstatuscode(Net.HttpStatusCode.NotFound, "NOTFOUND")
            Else
                context.setstatuscode(Net.HttpStatusCode.OK, "OK")
            End If
        Else
            raiseError("return empty xmlcontrol for request " + context.request.Url.ToString() + ", ignore request." _
                       , errorHandle.errorType.warning)
            context.setstatuscode(Net.HttpStatusCode.NotFound, "NOTFOUND")
        End If
        Try
            If context.response.ContentEncoding Is Nothing Then
                context.setcontentEncoding(encoding.utf8)
            End If
            If isemptystring(context.response.ContentType) Then
                context.setcontentType(network.http.contentType.texthtmlUtf8)
            End If
        Catch ex As Exception
            raiseError("failed to set response contentencoding and contenttype, " + _
                       context.url().full + ", " + ex.Message, errorHandle.errorType.warning)
        End Try
    End Sub
End Class

#End If
